package com.zxl.always.on.display.ui.helper;

import android.content.Context;
import android.provider.Settings;

/**
 * Created by Administrator on 2018/2/24.
 */

public class BrightnessHelper {

    private Context context;

    private boolean isCallRest;

    private int originalBrightness = 100;

    private int originalAutoBrightnessStatus;

    public BrightnessHelper(Context context) {
        this.context = context;
        isCallRest = true;
        originalAutoBrightnessStatus = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
        originalBrightness = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 100);
    }

    public void setBrightness() {
        if (isCallRest) {
            isCallRest = false;
            originalAutoBrightnessStatus = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
            originalBrightness = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 100);
        }
        Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 20);
        Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, 0);
    }

    public void resetBrightness(Context context) {
        if (!isCallRest) {
            isCallRest = true;
            Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, originalBrightness);
            Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, originalAutoBrightnessStatus);
        }
    }

}
